package com.buba.controller;


import com.buba.service.DeviceTypeService;
import common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buba.service.DeviceTypeService;
import com.buba.utils.TreeMenu;
import entity.device.DeviceType;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;
import java.util.List;

/**
 * <p>
 * 设备类型 前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-05-18
 */
@RestController
@RequestMapping("/device-type")
public class DeviceTypeController {
    @Autowired
    private DeviceTypeService deviceTypeService;

    @Autowired
    DeviceTypeService typeService;

    /**
     * @return common.R
     * @Author atlong
     * @Description 编辑设备类型信息
     * @Date 2023/6/1 14:29
     * @Param [deviceType]
     **/
    @PostMapping("updateDeviceType")
    public R updateDeviceType(@RequestBody DeviceType deviceType) {
        boolean b = typeService.updateDeviceType(deviceType);
        return b ? R.success() : R.error();
    }

    /**
     * @return common.R
     * @Author atlong
     * @Description 批量删除
     * @Date 2023/6/1 9:45
     * @Param [idArray]
     **/
    @PostMapping("delDeviceType")
    public R deleteAll(@RequestBody List<Integer> idArray) {
        boolean b = typeService.deleteAll(idArray);
        return b ? R.success() : R.error();
    }

    /**
     * @return common.R
     * @Author atlong
     * @Description 添加设备类型信息
     * @Date 2023/6/1 9:35
     * @Param [deviceType]
     **/
    @PostMapping("insDeviceType")
    public R insDeviceType(@RequestBody DeviceType deviceType) {
        boolean b = typeService.insDeviceType(deviceType);
        return b ? R.success() : R.error();
    }

    /**
     * @return common.R
     * @Author atlong
     * @Description 查 询设备信息
     * @Date 2023/6/1 9:33
     * @Param [deviceType]
     **/
    @RequestMapping("selDeviceType")
    public R selDeviceType(@RequestBody DeviceType deviceType) {
        List<DeviceType> list = typeService.selDeviceType(deviceType);
        return R.success(list);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 树形查询设备类型
     * @Date: 2023/5/22 14:36
     * @Return: common.R
     * @Param: []
     */

    @GetMapping("/selAllDeviceType")
    public R selAllDeviceType(){
       return R.success(deviceTypeService.selAllDeviceType());
    }
    /**
     * @return common.R
     * @Author atlong
     * @Description 树形查询可以使用的类型
     * @Date 2023/6/1 17:06
     * @Param []
     **/
    @GetMapping("selDevice")
    public R queryType() {
        List<DeviceType> list = typeService.queryType();
        return R.success(list);
    }

    /**
     * @return common.R
     * @Author atlong
     * @Description 批量启动
     * @Date 2023/6/1 14:39
     * @Param [idArray]
     **/
    @PostMapping("startUsing")
    public R startUsing(@RequestBody List<Integer> idArray) {
        boolean b = typeService.startUsing(idArray);
        return b ? R.success() : R.error();
    }

    /**
     * @return common.R
     * @Author atlong
     * @Description 批量停止
     * @Date 2023/6/1 14:39
     * @Param [idArray]
     **/
    @PostMapping("outService")
    public R outService(@RequestBody List<Integer> idArray) {
        boolean b = typeService.outService(idArray);
        return b ? R.success() : R.error();
    }
}



